function create_101_cards(thickness_inner,thickness_outer,id_cp,id_T,stru_up_rigid,stru_down_rigid,aero_up_pre,aero_down_pre,aerobox,stru_quad_up_plus,stru_quad_down_plus)
if ~all([exist('grid_101.bdf','file'),exist('rbe2.bdf','file'),exist('spc.bdf','file')])
    fgrid=fopen('grid.bdf','r');
    fgrid_101=fopen('grid_101.bdf','w');
    frbe2=fopen('rbe2.bdf','w');
    fspc=fopen('spc.bdf','w');
    i=900000;
    j=2;
    fprintf(fspc,'SPC1    %8d%8d',1,246);
    
    [xData,yData,zData]=prepareSurfaceData(stru_up_rigid(:,2),stru_up_rigid(:,3),stru_up_rigid(:,4));
    [fitresult_up,~]=fit([xData, yData],zData,'linearinterp','Normalize','on' );
    [xData,yData,zData]=prepareSurfaceData(stru_down_rigid(:,2),stru_down_rigid(:,3),stru_down_rigid(:,4));
    [fitresult_down,~]=fit([xData, yData],zData,'linearinterp','Normalize','on' );
    fix=get_fix;
    
    while true
        entry=fgetl(fgrid);
        if entry==-1
            break
        end
        id=sscanf(entry(9:16),'%d');
        x=sscanf(entry(25:32),'%f');
        y=sscanf(entry(33:40),'%f');
        z=sscanf(entry(41:length(entry)),'%f');
        fprintf(fgrid_101,'%s\n',entry(1:min(64,length(entry))));
        if ismember(id,stru_up_rigid(:,1))&&ismember(id,stru_down_rigid(:,1))
            [dx,dy,dz]=normal_n(x,y,fitresult_up);
            if dz>0.6||y<5||ismember(id,fix)
                dx=0; dy=0; dz=1;
            end
            fprintf(fgrid_101,'%s%8d%8s%8.2f%8.2f%8.2f\n',entry(1:8),id+100000,'',x+dx*thickness_inner,y+dy*thickness_inner,z+dz*thickness_inner);
            fprintf(fgrid_101,'%s%8d%8s%8.2f%8.2f%8.2f\n',entry(1:8),id+200000,'',x+dx*(thickness_inner+thickness_outer),y+dy*(thickness_inner+thickness_outer),z+dz*(thickness_inner+thickness_outer));
            [dx,dy,dz]=normal_n(x,y,fitresult_down);
            if dz>0.6||y<5||ismember(id,fix)
                dx=0; dy=0; dz=1;
            end
            fprintf(fgrid_101,'%s%8d%8s%8.2f%8.2f%8.2f\n',entry(1:8),id+300000,'',x-dx*thickness_inner,y-dy*thickness_inner,z-dz*thickness_inner);
            fprintf(fgrid_101,'%s%8d%8s%8.2f%8.2f%8.2f\n',entry(1:8),id+400000,'',x-dx*(thickness_inner+thickness_outer),y-dy*(thickness_inner+thickness_outer),z-dz*(thickness_inner+thickness_outer));
            if y==0
                fprintf(frbe2,'%s%8d%8d%s%8d%8d\n','RBE2    ',i,id,'   135  ',id+100000,id+300000);
            else
                fprintf(frbe2,'%s%8d%8d%s%8d%8d\n','RBE2    ',i,id,' 123456 ',id+100000,id+300000);
            end
            i=i+1;
        elseif ismember(id,stru_up_rigid(:,1))||ismember(id,stru_quad_up_plus(:,3:6))
            [dx,dy,dz]=normal_n(x,y,fitresult_up);
            if dz>0.6||y<5||ismember(id,fix)
                dx=0; dy=0; dz=1;
            end
            fprintf(fgrid_101,'%s%8d%8s%8.2f%8.2f%8.2f\n',entry(1:8),id+100000,'',x+dx*thickness_inner,y+dy*thickness_inner,z+dz*thickness_inner);
            fprintf(fgrid_101,'%s%8d%8s%8.2f%8.2f%8.2f\n',entry(1:8),id+200000,'',x+dx*(thickness_inner+thickness_outer),y+dy*(thickness_inner+thickness_outer),z+dz*(thickness_inner+thickness_outer));
            if y==0
                fprintf(frbe2,'%s%8d%8d%s%8d\n','RBE2    ',i,id,'   135  ',id+100000);
            else
                fprintf(frbe2,'%s%8d%8d%s%8d\n','RBE2    ',i,id,' 123456 ',id+100000);
            end
            i=i+1;
        elseif ismember(id,stru_down_rigid(:,1))||ismember(id,stru_quad_down_plus(:,3:6))
            [dx,dy,dz]=normal_n(x,y,fitresult_down);
            if dz>0.6||y<5||ismember(id,fix)
                dx=0; dy=0; dz=1;
            end
            fprintf(fgrid_101,'%s%8d%8s%8.2f%8.2f%8.2f\n',entry(1:8),id+300000,'',x-dx*thickness_inner,y-dy*thickness_inner,z-dz*thickness_inner);
            fprintf(fgrid_101,'%s%8d%8s%8.2f%8.2f%8.2f\n',entry(1:8),id+400000,'',x-dx*(thickness_inner+thickness_outer),y-dy*(thickness_inner+thickness_outer),z-dz*(thickness_inner+thickness_outer));
            if y==0
                fprintf(frbe2,'%s%8d%8d%s%8d\n','RBE2    ',i,id,'   135  ',id+300000);
            else
                fprintf(frbe2,'%s%8d%8d%s%8d\n','RBE2    ',i,id,' 123456 ',id+300000);
            end
            i=i+1;
        end
        if id==id_cp||id==id_T
            continue
        end
        if y==0
            fprintf(fspc,'%8d',id);
            j=j+1;
            if j==8
                fprintf(fspc,'\n        ');
                j=0;
            end
            if ismember(id,stru_up_rigid(:,1))||ismember(id,stru_quad_up_plus(:,3:6))
                fprintf(fspc,'%8d',id+100000);
                j=j+1;
                if j==8
                    fprintf(fspc,'\n        ');
                    j=0;
                end
                fprintf(fspc,'%8d',id+200000);
                j=j+1;
                if j==8
                    fprintf(fspc,'\n        ');
                    j=0;
                end
            end
            if ismember(id,stru_down_rigid(:,1))||ismember(id,stru_quad_down_plus(:,3:6))
                fprintf(fspc,'%8d',id);
                j=j+1;
                if j==8
                    fprintf(fspc,'\n        ');
                    j=0;
                end
                fprintf(fspc,'%8d',id+300000);
                j=j+1;
                if j==8
                    fprintf(fspc,'\n        ');
                    j=0;
                end
                fprintf(fspc,'%8d',id+400000);
                j=j+1;
                if j==8
                    fprintf(fspc,'\n        ');
                    j=0;
                end
            end
        end
    end
end

fmaterial=fopen('material_101.bdf','r');
fmaterial_new=fopen('material_101+.bdf','w');
fproperty=fopen('property.bdf','r');
fproperty_new=fopen('property+.bdf','w');
while feof(fmaterial)==0
    fprintf(fmaterial_new,'%s\n',fgetl(fmaterial));
end
while feof(fproperty)==0
    fprintf(fproperty_new,'%s\n',fgetl(fproperty));
end
fprintf(fproperty_new,'PSOLID   3       3       0\n');
fprintf(fproperty_new,'PSOLID   4       4       0\n');
fprintf(fmaterial_new,'MAT1     3      0.001           .01     2.56-7\n');
fprintf(fmaterial_new,'MAT1     4      1.09+8          .31     8.24-6  1.1-5   293.');
fclose('all');
!del material_101.bdf
!rename material_101+.bdf material_101.bdf
!del property.bdf
!rename property+.bdf property.bdf

ftria=fopen('tria.bdf','r');
fpenta=fopen('penta.bdf','w');
fhexa=fopen('hexa.bdf','w');
for i=1:size(aerobox,1)
    if ismember(aerobox(i,1),aero_up_pre(:,1))
        fprintf(fhexa,'%8s%8d%8d%8d%8d%8d%8d%8d%8d\n','CHEXA   ',aerobox(i,1)+100000,3,aerobox(i,2),aerobox(i,6),aerobox(i,10),aerobox(i,14),aerobox(i,2)+100000,aerobox(i,6)+100000);
        fprintf(fhexa,'%8s%8d%8d\n',' ',aerobox(i,10)+100000,aerobox(i,14)+100000);
        fprintf(fhexa,'%8s%8d%8d%8d%8d%8d%8d%8d%8d\n','CHEXA   ',aerobox(i,1)+200000,4,aerobox(i,2)+100000,aerobox(i,6)+100000,aerobox(i,10)+100000,aerobox(i,14)+100000,aerobox(i,2)+200000,aerobox(i,6)+200000);
        fprintf(fhexa,'%8s%8d%8d\n',' ',aerobox(i,10)+200000,aerobox(i,14)+200000);
    elseif ismember(aerobox(i,1),aero_down_pre(:,1))
        fprintf(fhexa,'%8s%8d%8d%8d%8d%8d%8d%8d%8d\n','CHEXA   ',aerobox(i,1)+100000,3,aerobox(i,2),aerobox(i,6),aerobox(i,10),aerobox(i,14),aerobox(i,2)+300000,aerobox(i,6)+300000);
        fprintf(fhexa,'%8s%8d%8d\n',' ',aerobox(i,10)+300000,aerobox(i,14)+300000);
        fprintf(fhexa,'%8s%8d%8d%8d%8d%8d%8d%8d%8d\n','CHEXA   ',aerobox(i,1)+200000,4,aerobox(i,2)+300000,aerobox(i,6)+300000,aerobox(i,10)+300000,aerobox(i,14)+300000,aerobox(i,2)+400000,aerobox(i,6)+400000);
        fprintf(fhexa,'%8s%8d%8d\n',' ',aerobox(i,10)+400000,aerobox(i,14)+400000);
    end
end
for i=1:size(stru_quad_up_plus,1)
    if stru_quad_up_plus(i,1)==-1
        break
    end
    fprintf(fhexa,'%8s%8d%8d%8d%8d%8d%8d%8d%8d\n','CHEXA   ',stru_quad_up_plus(i,1)+100000,3,stru_quad_up_plus(i,3),stru_quad_up_plus(i,4),stru_quad_up_plus(i,5),stru_quad_up_plus(i,6),stru_quad_up_plus(i,3)+100000,stru_quad_up_plus(i,4)+100000);
    fprintf(fhexa,'%8s%8d%8d\n',' ',stru_quad_up_plus(i,5)+100000,stru_quad_up_plus(i,6)+100000);
    fprintf(fhexa,'%8s%8d%8d%8d%8d%8d%8d%8d%8d\n','CHEXA   ',stru_quad_up_plus(i,1)+200000,3,stru_quad_up_plus(i,3)+100000,stru_quad_up_plus(i,4)+100000,stru_quad_up_plus(i,5)+100000,stru_quad_up_plus(i,6)+100000,stru_quad_up_plus(i,3)+200000,stru_quad_up_plus(i,4)+200000);
    fprintf(fhexa,'%8s%8d%8d\n',' ',stru_quad_up_plus(i,5)+200000,stru_quad_up_plus(i,6)+200000);
end
for i=1:size(stru_quad_down_plus,1)
    if stru_quad_down_plus(i,1)==-1
        break
    end
    fprintf(fhexa,'%8s%8d%8d%8d%8d%8d%8d%8d%8d\n','CHEXA   ',stru_quad_down_plus(i,1)+100000,3,stru_quad_down_plus(i,3),stru_quad_down_plus(i,4),stru_quad_down_plus(i,5),stru_quad_down_plus(i,6),stru_quad_down_plus(i,3)+300000,stru_quad_down_plus(i,4)+300000);
    fprintf(fhexa,'%8s%8d%8d\n',' ',stru_quad_down_plus(i,5)+100000,stru_quad_down_plus(i,6)+100000);
    fprintf(fhexa,'%8s%8d%8d%8d%8d%8d%8d%8d%8d\n','CHEXA   ',stru_quad_down_plus(i,1)+200000,3,stru_quad_down_plus(i,3)+300000,stru_quad_down_plus(i,4)+300000,stru_quad_down_plus(i,5)+300000,stru_quad_down_plus(i,6)+300000,stru_quad_down_plus(i,3)+400000,stru_quad_down_plus(i,4)+400000);
    fprintf(fhexa,'%8s%8d%8d\n',' ',stru_quad_down_plus(i,5)+400000,stru_quad_down_plus(i,6)+400000);
end
while feof(ftria)==0
    entry=fgetl(ftria);
    if length(entry)==1
        disp('Have no tria.')
        break
    end
    stru_tria=sscanf(entry(9:length(entry)),'%d%d%d%d%d');
    if ismember(stru_tria(3),stru_up_rigid)&&ismember(stru_tria(4),stru_up_rigid)&&ismember(stru_tria(5),stru_up_rigid)
        fprintf(fpenta,'%8s%8d%8d%8d%8d%8d%8d%8d%8d\n','CPENTA  ',stru_tria(1)+100000,3,stru_tria(3),stru_tria(4),stru_tria(5),stru_tria(3)+100000,stru_tria(4)+100000,stru_tria(5)+100000);
        fprintf(fpenta,'%8s%8d%8d%8d%8d%8d%8d%8d%8d\n','CPENTA  ',stru_tria(1)+200000,4,stru_tria(3)+100000,stru_tria(4)+100000,stru_tria(5)+100000,stru_tria(3)+200000,stru_tria(4)+200000,stru_tria(5)+200000);
    elseif ismember(stru_tria(3),stru_down_rigid)&&ismember(stru_tria(4),stru_down_rigid)&&ismember(stru_tria(5),stru_down_rigid)
        fprintf(fpenta,'%8s%8d%8d%8d%8d%8d%8d%8d%8d\n','CPENTA  ',stru_tria(1)+100000,3,stru_tria(3),stru_tria(4),stru_tria(5),stru_tria(3)+300000,stru_tria(4)+300000,stru_tria(5)+300000);
        fprintf(fpenta,'%8s%8d%8d%8d%8d%8d%8d%8d%8d\n','CPENTA  ',stru_tria(1)+200000,4,stru_tria(3)+300000,stru_tria(4)+300000,stru_tria(5)+300000,stru_tria(3)+400000,stru_tria(4)+400000,stru_tria(5)+400000);
    end
end
fclose('all');
end